def main():
# 用列表存储所有AI助手，每个助手以字典形式表示
    assistants = []

# 添加预设AI助手
    default_assistants = [
        {"id": "101", "name": "小智", "type": "语音助手", "version": "v1.2", "online": True, "score": 95},
        {"id": "102", "name": "编小助", "type": "编程助手", "version": "2.1", "online": True, "score": 90},
        {"id": "103", "name": "翻译精灵", "type": "语言翻译", "version": "1.8", "online": False, "score": 88},
        {"id": "104", "name":  "图灵", "type": "图像生成", "version": "4.0", "online": True, "score": 92},
        {"id": "105", "name": "数小析", "type": "数据分析", "version": "2.5", "online": False, "score": 85}
    ]
    assistants.extend(default_assistants)

    while True:
        print("""
========== AI助手管理器 ==========
1. 查看所有AI助手列表
2. 根据ID查询助手详情
3. 添加新的AI助手
4. 根据ID修改助手信息
5. 删除AI助手（按ID）
6. 启动AI助手服务
7. 停止AI助手服务
8. 为AI助手分配任务
9. 显示系统统计信息
0. 退出系统
===================================
""")
        choice = input("请选择操作: ")

        # 1. 查看所有助手信息
        if choice == "1":
            if not assistants:
                print("暂无AI助手")
            else:
                for a in assistants:
                    status = "🟢在线" if a["online"] else "🔴离线"
                    print(
                        f"ID: {a['id']}, 名称: {a['name']}, 类型: {a['type']}, 版本: {a['version']}, 状态: {status}, 能力评分: {a['score']}")

        # 2. 根据ID查询相关助手
        elif choice == "2":
            aid = input("请输入ID: ")
            found = next((a for a in assistants if a["id"] == aid), None)
            if found:
                status = "🟢在线" if found["online"] else "🔴离线"
                print(
                    f"ID: {found['id']}, 名称: {found['name']}, 类型: {found['type']}, 版本: {found['version']}, 状态: {status}, 能力评分: {found['score']}")
            else:
                print("❌ 未找到该助手")

        # 3. 添加新助手
        elif choice == "3":
            aid = input("请输入ID: ")
            if any(a["id"] == aid for a in assistants):
                print("❌ ID已存在，添加失败")
                continue

            new_assistant = {
                "id": aid,
                "name": input("请输入名称: "),
                "type": input("请输入类型: "),
                "version": input("请输入版本号: "),
                "online": input("是否在线？(1-是,0-否): ") == "1",
                "score": int(input("请输入能力评分: "))
            }
            assistants.append(new_assistant)
            print(f"✅ 助手【{new_assistant['name']}】添加成功！")

        # 4. 根据序号修改助手信息
        elif choice == "4":
            aid = input("请输入ID: ")
            target = next((a for a in assistants if a["id"] == aid), None)
            if not target:
                print("❌ 未找到该助手")
                continue

            attr, value = input("请输入属性和值(如 score 90): ").split()
            if attr not in target:
                print("❌ 无效属性")
                continue
        # 5. 删除AI助手
        elif choice == "5":
            aid = input("请输入ID: ")
            target = next((a for a in assistants if a["id"] == aid), None)
            if target:
                assistants.remove(target)
                print(f"✅ 助手【{target['name']}】已删除")
            else:
                print("❌ 未找到该助手")

        # 6. 启动AI助手服务
        elif choice == "6":
            aid = input("请输入ID: ")
            target = next((a for a in assistants if a["id"] == aid), None)
            if target:
                target["online"] = True
                print(f"助手【{target['name']}】已在运行")
            else:
                print("❌ 未找到该助手")

        # 7. 停止服务
        elif choice == "7":
            aid = input("请输入ID: ")
            target = next((a for a in assistants if a["id"] == aid), None)
            if target:
                target["online"] = False
                print(f"✅ 助手【{target['name']}】已停止")
            else:
                print("❌ 未找到该助手")

        # 8. 分配任务
        elif choice == "8":
            aid = input("请输入ID: ")
            target = next((a for a in assistants if a["id"] == aid), None)
            if not target:
                print("❌ 未找到该助手")
                continue

            task = input("请输入任务内容: ")
            if target["online"]:
                print(f"任务已分配给【{target['name']}】: {task}")
            else:
                print(f"❌ {target['name']} 当前离线，无法执行任务")

        # 9. 显示统计信息
        elif choice == "9":
            total = len(assistants)
            online = sum(1 for a in assistants if a["online"])
            offline = total - online
            avg_score = sum(a["score"] for a in assistants) / total if total else 0
            print(f"""
系统统计信息：
总助手数: {total}
在线助手数: {online}
离线助手数: {offline}
平均能力评分: {avg_score:.2f}
""")

        # 0. 退出系统
        elif choice == "0":
            print("系统已退出，ヾ(•ω•`)o期待与你的下次再见。")
            break

        else:
            print("❌ 无效选项，请重新输入")


if __name__ == "__main__":
    main()